<?php


namespace App\Http\observer;


use App\Http\service\XcxService;
use App\Models\GoodsOrder;
use App\Models\Goods;
use App\Models\User;

class GoodsOrderObserver
{
    public function created(GoodsOrder $order)
    {
        Goods::where("id",$order["goods_id"])->decrement("stock",1);
        User::where("id",$order["uid"])->decrement("coupon",$order["price"]);
        $scene="type=goods_code&id=".$order["id"];
        $path=(new XcxService())->create_xcx_code($scene);
        GoodsOrder::where("id",$order["id"])->update(["qrcode"=>$path]);
    }
}
